package io.xiaojl.xj2ee.common.kit.json;

import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.TimeZone;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonGenerator.Feature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

/**
 * 
 * <p>Title: JacksonObjectMapper</p>  
 *
 * <p>Description: 解决Jackson 差8小时的问题</p>  
 *
 * @author jilong.xiao  
 * @date 2018年5月23日
 */
public class JacksonObjectMapper extends ObjectMapper {

    private static final long serialVersionUID = 4288193147502386170L;

    private static final Locale CHINA = Locale.CHINA;
    
    public JacksonObjectMapper() {
        this.setLocale(CHINA);
        this.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", CHINA));
        this.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        
        // 全局配置序列化返回 JSON 处理:ID_WORKER 主键 Long 导致 js 精度丢失
        this.configure(Feature.WRITE_NUMBERS_AS_STRINGS, true);
        
        //处理json返回乱码问题
        this.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        this.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
        this.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
        
    }

}
